package com.jn.erp.web.api.course.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageInfo;
import com.jn.erp.common.constant.HttpStatus;
import com.jn.erp.common.core.page.TableDataInfo;
import com.jn.erp.common.core.result.AjaxResult;
import com.jn.erp.security.controller.BaseWebAuthController;
import com.jn.erp.web.api.course.entity.dto.TCourseDto;
import com.jn.erp.web.api.course.entity.vo.TCourseVo;
import com.jn.erp.web.api.course.service.TCourseService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wyp
 * @since 2024-08-29
 */
@RestController
@RequestMapping("/tCourse")
public class TCourseController extends BaseWebAuthController {
    @Autowired
    private TCourseService tCourseService;
    /**
    课程新建
     */
    @PostMapping("save")
    public AjaxResult save(@RequestBody TCourseVo tCourseVo){
        //机构id
        tCourseVo.setOrgId(Long.parseLong(loginDeptAuth()) );
        //当前登录人id
        tCourseVo.setCreateUser(String.valueOf(getUserId()) );
        String code = tCourseService.saveCourse(tCourseVo);
        return AjaxResult.success(code);
    }

    /**
     课程列表
     */
    @GetMapping("list")
    public TableDataInfo list(TCourseVo tCourseVo){
        startPage();
        //机构id
        tCourseVo.setOrgId(Long.parseLong(loginDeptAuth()) );
        //当前登录人id
        tCourseVo.setCreateUser(String.valueOf(getUserId()) );
        tCourseVo.setPOrgId(Long.parseLong(loginDeptParentAuth()) );
        List<TCourseDto> list = tCourseService.courseList(tCourseVo);
        return getDataTable(list);
    }

    /**
     课程删除
     */
    @PostMapping("update")
    public AjaxResult update(@RequestBody TCourseVo tCourseVo){
        //机构id
        tCourseVo.setOrgId(Long.parseLong(loginDeptAuth()) );
        //当前登录人id
        tCourseVo.setCreateUser(String.valueOf(getUserId()) );
        String code = tCourseService.updateCourse(tCourseVo);
        return AjaxResult.success(code);
    }

    /**
     课程删除
     */
    @PostMapping("delete")
    public AjaxResult delete(@RequestBody TCourseVo tCourseVo){
        //机构id
        tCourseVo.setOrgId(Long.parseLong(loginDeptAuth()) );
        //当前登录人id
        tCourseVo.setCreateUser(String.valueOf(getUserId()) );
        tCourseVo.setIsDelete("1");
        Boolean boo = tCourseService.deleteCourse(tCourseVo);
        return AjaxResult.success(boo);
    }
}

